﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace StuDataType
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            //byte  1个byte=8bit
            //2个字节 short/ushort/Int16/Int16 short:-32,768~32,767   ushort:0-65535
            //4个字节 int/uint/Int32/uint32/float(精度丢失)
            //8个字节 long/ulong/int64/uint64/double
            //16个字节 decimal

            // 一般硬件资源有限,比如double m = 36.8;直接有ushort存:368。取出来做转换368*0.1或者368/10

            //  UInt16 n = 69;
            //  //数字转成字节byte[]
            //byte[] bytes=  BitConverter.GetBytes(n);

            //int n = 69;
            // //数字转成字节byte[]
            // byte[] bytes = BitConverter.GetBytes(n);

            //decimal n = 69;
            ////数字转成字节byte[]
            //byte[] bytes = BitConverter.GetBytes(n);

            // 16进制表示4个字节的整型
            //uint i = 0x0000001F;  // 断点查看结果31(16+15=31)


            //数字和字节数字互相转换BitConverter
            //byte[]数组转成数字
            //0x2C=32+12
            byte[] bytes = {              // 小端写法,数据低位在内存低地址
                0x2C,0x01,0x00,0x00
            };

            int m = BitConverter.ToInt32(bytes);  // C# BitConverter是小端转换

            //字符串的转换
            //UTF-8一个汉字以3个字节存储,其中2个字节=16位 ,还需要5个bit处理编码
            //英文还是按一个字节存储
            string str = "abc我";
            byte[] strBytes = Encoding.UTF8.GetBytes(str);

            //byte[]转string
            string strResult = Encoding.UTF8.GetString(strBytes);
        }
    }
}